package library.operation;

import library.Book;
import library.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {//借书
        System.out.println("借书");
        //需要让用户输入借书的编号
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入需要借阅书的编号");
        int id = scanner.nextInt();
        if(id<0||id>=bookList.getSize()){
            System.out.println("输入的编号不存在");
        }
        Book book = bookList.getBook(id);
        if(book.isBorrowed()){
            System.out.println("该书已被借阅");
            return;
        }
        book.setBorrowed(true);
        System.out.println("借阅成功");


    }
}
